/**
 * @author 何杰
 * @version 1.0
 */
public class maxArea {
    public static void main(String[] args) {
        int[] test = {1,8,6,2,5,4,8,3,7};
        System.out.println(maxArea(test));
    }

    public static int maxArea(int[] height) {
        //1,8,6,2,5,4,8,3,7
//        int[] test = {1,8,6,2,5,4,8,3,7};
        int max_area = -1, left = 0,right = height.length - 1;
        while(left < right) {
            max_area = Math.max(max_area, Math.min(height[left], height[right]) * (right - left));
            if(height[left] <= height[right]) {
                left++;
            } else {
                right--;
            }
        }
        return max_area;
    }
}
